﻿@model BudgetMealsModels.Entities.Comment
@if (Model != null)
{
<div id="Review@(Model.CommentID)">
    <p style="margin-top: 25px;">
        <b>Rating: </b>@Model.RecipeRating
    </p>
    <p>
        <b>Comment: </b>
    </p>
    <p style="margin-left: 25px;">@Model.Review</p>
    <p id="reviewer">
        <i>
            Review by @Html.ActionLink(Model.UserCreated, "Profile", "User", new { id = Model.UserCreatedID }, null)
        </i>
    </p>
    @if (Session["CurrentUser"] != null && Model.UserCreatedID == (int)Session["CurrentUser"])
    {
        @*@Html.ActionLink("Delete", "Delete", "Comment", new { id = Model.CommentID, stringURL = Request.Url.PathAndQuery }, null);*@
        <span class="PseudoLink" id="Delete@(Model.CommentID)" onclick="DeleteReview(@Model.CommentID)">Delete</span>
    }
 
    <span class="PseudoLink" id="ReplyLink@(Model.CommentID)" onclick="toggleVisibility(@Model.CommentID)">Reply</span>
    <script type="text/javascript">
        function getVisibility(commentID) {
        var temp = document.getElementById("reply " + commentID).style.visibility;
        return temp;
        }
        function toggleVisibility(commentID) {
            var current = getVisibility(commentID);
            if (current == "visible") {
                document.getElementById("reply " + commentID).style.visibility = "hidden";
                document.getElementById("reply " + commentID).style.height = "0";
            }
            else {
                document.getElementById("reply " + commentID).style.visibility = "visible";
                document.getElementById("reply " + commentID).style.height = "auto";
            }
        }
    </script>
    <div id="Replies@(Model.CommentID)" style="margin-left: 50px;">
        @{
            if (Model.HierarchicalComments != null)
            {
                foreach (var reply in Model.HierarchicalComments)
                {
                    Html.RenderPartial("../Comment/ShowReply", reply);
                }
            }
        }
     </div>
    <div id="reply @Model.CommentID" style="visibility:hidden; height: 0; margin-left: 50px;">
        @{Html.RenderAction("AddComment", "Comment", new { commentId = 0, recipeId = Model.Recipe.RecipeID, parentId = Model.CommentID });}
    </div>
    
</div>
}